package com.hpq.common.domain.vo.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.hpq.common.exception.HttpStatusEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("基础返回体")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ApiResult<T> {
    @ApiModelProperty(value = "成功标识")
    private Boolean success;
    @ApiModelProperty(value = "错误码")
    private Integer errCode;
    @ApiModelProperty(value = "错误信息")
    private String errMsg;
    @ApiModelProperty(value = "返回数据")
    private T data;
    public static <T> ApiResult<T> success(){
            ApiResult<T>  result  = new ApiResult<T>();
            result.setSuccess(Boolean.TRUE);
            result.setData(null);
            return result;
    }
    public static <T> ApiResult<T> success(T data){
        ApiResult<T>  result  = new ApiResult<T>();
        result.setSuccess(Boolean.TRUE);
        result.setData(data);
        return result;
    }

    public static <T> ApiResult<T> error(Integer errCode,String errMsg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.FALSE);
        result.setErrCode(errCode);
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> ApiResult<T> error(HttpStatusEnum errorEnum) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.FALSE);
        result.setErrCode(errorEnum.getCode());
        result.setErrMsg(errorEnum.getDesc());
        return result;
    }





}
